<!--
 * @Author: HeAo
 * @Date: 2021-09-29 14:35:59
 * @LastEditTime: 2021-09-29 14:52:26
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-1-ES6\day05\2-promise-ajax.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>promise-ajax</title>
  <script src="./jquery.js"></script>
  <script>
    const baseUrl = 'http://47.94.46.113:8888'
    const promise = new Promise((resolve, reject) => {
      $.ajax({
        url: baseUrl + '/index/category/findAll',
        method: 'get',
        success(res) {
          // 异步请求成功，调用resolve将成功的结果当做实参传递出去
          resolve(res)
        },
        error(err) {
          // 异步请求失败，调用reject将失败的结果当做实参传递出去
          reject(err)
        }
      })
    })

    // 通过promise的实例方法，访问其内部的状态，并拿到异步请求的响应结果
    promise.then(res => {
      console.log(res);
    }).catch(err => {
      console.log(err);
    })

  </script>
</head>

<body>

</body>

</html>